from selenium.webdriver.common.by import By
from base.base import Base
from util.number_util import get_all_number


class Page_Monitoring(Base):


    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[3]')
    input_siteseach_locator = (By.CLASS_NAME,'ant-select-selection-search-input')
    site_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    input_seachdevice_locator = (By.XPATH,'//input[@placeholder="设备搜索"]')
    device_errinfo_locator = (By.XPATH,'(//p[@class="ant-empty-description"])[1]')
    device_locator = (By.XPATH,'//span[text()=" xq测试-通用测温"]')                                #####需优化
    device_top_title_locator = (By.XPATH,'//div[@class="ant-card monitor-title"]')
    device_info_locator = (By.XPATH,'(//div[@class="ant-card"])[1]')
    device_runstate_locator = (By.CLASS_NAME,'ele-dashboard-inner')
    device_number = (By.CLASS_NAME,'number')
    alarm_list_locator = (By.XPATH,'//td[contains(@class,"ant-table-cell")]')



    def page_jump(self):
        self.click(self.topnav_locator)
        

    def input_site(self,sitename):
        self.input(self.input_siteseach_locator,sitename)

    def click_site(self):
        self.click(self.site_locator)

    def input_device(self,devicename):
        self.input(self.input_seachdevice_locator,devicename)
    
    def get_device_errorinfo(self):
        return self.get_text(self.device_errinfo_locator)
    
    def click_device(self):
        self.click(self.device_locator)

    def get_device_title(self):
        return self.get_text(self.device_top_title_locator)
    
    #获取设备信息，id=1，返回采集时间  id=2，返回设备状态
    def get_device_info(self,id = 1):   
        values = []
        info_list= self.get_text(self.device_info_locator).split('\n')
        for info in info_list:
            values.append(info.split('：')[1])
        if id == 1:
            return values[0]
        elif id == 2:
            return values[1]
        
    def get_device_runstate(self):
        values = []
        states = self.finds(self.device_runstate_locator)
        for state in states:
            values.append(self.get_text_elm(state))
        return values
    
    def get_device_number(self):
        values = []
        numbers = self.finds(self.device_number)
        for number in numbers:
            values.append(self.get_text_elm(number))
        return values
    
    def get_alarmlist(self):
        values = []
        for elm in self.finds(self.alarm_list_locator):
            values.append(self.get_text_elm(elm))
        return values